package com.chigga.admin.controller;

import com.chigga.admin.domain.entity.AdminDO;
import com.chigga.admin.service.AdminService;
import com.chigga.common.core.domain.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "后台管理接口", description = "后台管理接口描述")
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService adminService;

    /**
     * 无参
     */
    @GetMapping
    @Operation(summary = "无参测试接口", description = "无参测试接口描述")
    public ResponseResult<String> admin() {
        return ResponseResult.success("admin 模块");
    }

    /**
     * 一参
     * @param id 参数id
     */
    @GetMapping("/param")
    @Operation(summary = "一个参数测试接口", description = "一个参数测试接口描述")
    @Parameter(name = "id", description = "id参数", required = true, example = "1024")
    public ResponseResult<String> oneParam(String id) {
        return ResponseResult.success("一个参数" + id);
    }

    /**
     * 多参
     * @param id 参数id
     * @param name 参数名
     */
    @GetMapping("/params")
    @Operation(summary = "多个参数测试接口", description = "多个参数测试接口描述")
    @Parameters({
            @Parameter(name = "id", description = "id参数", required = true, example = "1024"),
            @Parameter(name = "name", description = "name参数", required = true, example = "DefChigga")
    })
    public ResponseResult<String> multiParam(String id, String name) {
        return ResponseResult.success("多个参数" + id + " " + name);
    }

    /**
     * 实体
     */
    @GetMapping("/entity")
    @Operation(summary = "实体测试接口", description = "实体测试接口描述")
    public ResponseResult<AdminDO> get() {
        return ResponseResult.success(AdminDO.builder().id("1024").name("DefChigga").build());
    }

    /**
     * 一个实体参数
     * @param adminDO 实体参数
     * @return admin 实体
     */
    @PostMapping("/entity/param")
    @Operation(summary = "实体参数测试接口", description = "实体参数测试接口描述")
    public ResponseResult<AdminDO> getEntity(@Valid @RequestBody AdminDO adminDO) {
        return ResponseResult.success(adminDO);
    }

    /**
     * 测试 TimeAspect 计时切面
     * @return 成功字符串
     */
    @GetMapping("/testTimeAspect")
    @Operation(summary = "测试 TimeAspect 计时切面", description = "测试切面描述")
    public ResponseResult<List<AdminDO>> testTimeAspect() {
        return ResponseResult.success(adminService.testTimeAspect());
    }
}
